<template>
  <div class="common-head">
    <div class="head-up">
      <!-- 头部左边 -->
      <div class="fl">
        <!-- 折叠图标 -->
        <i @click="toggleMenu" :class="$store.state.base.navCollapse?'el-icon-s-unfold':'el-icon-s-fold'">
        </i>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/dashBoard' }">首页</el-breadcrumb-item>
          <!-- 判断如果点击不是主页，名称显示在面包屑 -->
          <el-breadcrumb-item
            v-if="($route.path !== '/dashBoard')&&($route.path!=='/addGood')&&($route.path!=='/upDataGoods')">
            {{$route.name}}
          </el-breadcrumb-item>
          <el-breadcrumb-item v-if="($route.path == '/addGood')||($route.path == '/upDataGoods')"
            :to="{ path: 'goodList' }">
            用户列表</el-breadcrumb-item>
          <el-breadcrumb-item v-if=" $route.path=='/addGood' ">新增商品</el-breadcrumb-item>
          <el-breadcrumb-item v-if=" $route.path=='/upDataGoods'">更新商品</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <!-- 头部右边 -->
      <div class="head-fr">
        <el-dropdown @command="logOut">
          <div class="user-info">
            <span>{{$store.state.user.userInfo.username}}</span>
            <el-avatar :size="40" :src="$store.state.user.userInfo.userImg"></el-avatar>
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    toggleMenu () {
      this.$store.commit('base/TOGGLE_MENU')
    },
    // 退出登录
    logOut (tag) {
      if (tag == 'logout') {
        this.$store.commit('user/USER_LOGOUT')
        this.$store.commit('base/DEL_ALLTA')
        this.$message({
          type: 'success',
          message: '退出登录',
          duration: 1000,
          onClose: () => {
            this.$router.replace('/login')
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.common-head {

  // 头部上半部分
  .head-up {
    height: 70px !important;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgb(211, 211, 211);

    // 头部左边
    .fl {
      i {
        margin: 0px 15px;
        font-size: 20px;
      }

      display: flex;
      line-height: 70px;
      align-items: center;
    }

    // 头部右边
    .head-fr {
      display: flex;
      align-items: center;
      cursor: pointer;

      .user-info {
        display: flex;
        align-items: center;
        height: 60px;
      }

      span {
        margin-right: 10px;
      }
    }
  }
}
</style>
